import { defineStore } from "pinia";
import { ref } from "vue";

export const useUserInfoStore = defineStore('userInfo',
  () => {
    // 定义变量
    const userInfo = ref({})
    const token = ref('')
    const menuList = ref([])

    // 设置用户信息
    const setUserInfo = (newUserInfo) => {
      userInfo.value = newUserInfo
    }

    // 设置token
    const setToken = (newToken) => {
      token.value = newToken
    }

    // 设置菜单列表
    const setMenuList = (newMenuList) => {
      menuList.value = newMenuList
    }

    // 清理值
    const removeUserInfo = () => {
      userInfo.value = {}
      token.value = ''
      menuList.value = []
    }

    // 获取token
    const getToken = () => {
      return token.value
    }

    // 获取菜单列表
    const getMenuList = () => {
      return menuList.value
    }

    return {
      userInfo, token, menuList,
      setUserInfo, setToken, setMenuList,
      removeUserInfo, getToken, getMenuList
    }
  },
  {
    persist: true
  });